home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 125 / Computer Shopper CD-ROM Issue 125 (1998-07)(Dennis Publishing).iso / Business / Dazzler / DAZZLER.Z / CCheckButtonResponse.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-26  |  5.6 KB  |  305 lines

  1. import java.awt.Color;
  2. import java.awt.Event;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.awt.Toolkit;
  6. import java.io.DataInputStream;
  7. import java.util.NoSuchElementException;
  8.  
  9. public class CCheckButtonResponse extends CDisplayResponse {
  10.    public static final int SPACING = 5;
  11.    private CFontObject m_Font = new CFontObject();
  12.    private String m_strText;
  13.    private short m_cPrefixChar;
  14.    private int m_nFlags;
  15.    private Color m_rgbFg = new Color(0, 0, 0);
  16.    private Color m_rgbBg = new Color(0, 0, 0);
  17.    private String m_strSetExpression;
  18.    private short m_wState = 0;
  19.    private String m_strVarText = "";
  20.    private CRect m_rcSymbol = new CRect();
  21.  
  22.    boolean LoadFromFile(DataInputStream var1) {
  23.       this.m_Font.LoadFromFile(var1);
  24.       this.m_strText = FileLoad.ReadCString(var1);
  25.       this.m_strSetExpression = FileLoad.ReadCString(var1);
  26.       this.m_cPrefixChar = FileLoad.ReadCPlusByte(var1);
  27.       this.m_nFlags = FileLoad.ReadCPlusInt(var1);
  28.       this.m_rgbFg = FileLoad.ReadColor(var1);
  29.       this.m_rgbBg = FileLoad.ReadColor(var1);
  30.       return super.LoadFromFile(var1);
  31.    }
  32.  
  33.    public short GetAnswer() {
  34.       byte var1 = 2;
  35.       if ((this.m_wState & 16) != 0 && super.m_cLogType == 1 || (this.m_wState & 16) == 0 && super.m_cLogType == 2) {
  36.          var1 = 1;
  37.       }
  38.  
  39.       return (short)var1;
  40.    }
  41.  
  42.    public CCheckButtonResponse() {
  43.       super(25);
  44.    }
  45.  
  46.    public void DoEntryResponse() {
  47.       this.DoResponse(0);
  48.    }
  49.  
  50.    private void ResetRadioButtonGroup() {
  51.       CDrawObj var1 = null;
  52.       Object var2 = null;
  53.       CCheckButtonResponse var3 = null;
  54.       boolean var4 = false;
  55.       synchronized(Globals.thePresView.m_DrawObjectList){}
  56.  
  57.       try {
  58.          try {
  59.             var1 = Globals.thePresView.m_DrawObjectList.GetHead();
  60.          } catch (NoSuchElementException var13) {
  61.             var4 = true;
  62.          }
  63.  
  64.          while(!var4) {
  65.             if (var1 != null) {
  66.                if (var1.GetIconObject().GetTypeID() == 25) {
  67.                   CCheckButtonResponse var15 = (CCheckButtonResponse)var1.GetIconObject();
  68.                   if ((var15.GetFlags() & 128) != 0) {
  69.                      if ((var15.GetFlags() & 32) != 0) {
  70.                         var3 = null;
  71.                      }
  72.  
  73.                      if (Utils.StateTest(var15.GetState(), 16)) {
  74.                         var3 = var15;
  75.                      }
  76.                   }
  77.                }
  78.  
  79.                if (var1.GetIconObject().equals(this)) {
  80.                   break;
  81.                }
  82.             }
  83.  
  84.             try {
  85.                var1 = Globals.thePresView.m_DrawObjectList.GetNext();
  86.             } catch (NoSuchElementException var12) {
  87.                var4 = true;
  88.             }
  89.          }
  90.  
  91.          while(!var4 && var3 == null) {
  92.             try {
  93.                var1 = Globals.thePresView.m_DrawObjectList.GetNext();
  94.             } catch (NoSuchElementException var11) {
  95.                var4 = true;
  96.             }
  97.  
  98.             if (var1 != null && !var4 && var1.GetIconObject().GetTypeID() == 25) {
  99.                CCheckButtonResponse var16 = (CCheckButtonResponse)var1.GetIconObject();
  100.                if ((var16.GetFlags() & 128) != 0) {
  101.                   if ((var16.GetFlags() & 32) != 0) {
  102.                      break;
  103.                   }
  104.  
  105.                   if (Utils.StateTest(var16.GetState(), 16)) {
  106.                      var3 = var16;
  107.                   }
  108.                }
  109.             }
  110.          }
  111.       } catch (Throwable var14) {
  112.          throw var14;
  113.       }
  114.  
  115.       if (var3 != null && !var4) {
  116.          var3.SetState((short)Utils.StateClear(var3.GetState(), 16));
  117.          Globals.thePresView.Render(var3.m_rcSymbol);
  118.          Globals.thePresView.Draw((Graphics)null, var3.m_rcSymbol);
  119.       }
  120.  
  121.    }
  122.  
  123.    private void ToggleState() {
  124.       if (Utils.StateTest(this.m_wState, 16)) {
  125.          this.m_wState = (short)Utils.StateClear(this.m_wState, 16);
  126.       } else {
  127.          this.m_wState = (short)Utils.StateSet(this.m_wState, 16);
  128.       }
  129.  
  130.       Globals.thePresView.Render(this.m_rcSymbol);
  131.       Globals.thePresView.Draw((Graphics)null, this.m_rcSymbol);
  132.    }
  133.  
  134.    public void SetState(short var1) {
  135.       this.m_wState = var1;
  136.    }
  137.  
  138.    public int GetFlags() {
  139.       return this.m_nFlags;
  140.    }
  141.  
  142.    public boolean OnKeyPress(int var1, Event var2) {
  143.       if (this.m_cPrefixChar != 0 && var1 == Character.toUpperCase((char)this.m_cPrefixChar)) {
  144.          this.ToggleState();
  145.       }
  146.  
  147.       return false;
  148.    }
  149.  
  150.    public CResponseReturn DoResponse(int var1) {
  151.       CResponseReturn var2 = new CResponseReturn(0, var1);
  152.       if (Utils.StateTest(this.m_wState, 16) && super.m_strVariableString.length() > 0) {
  153.          Utils.SetVariables(super.m_strVariableString, false);
  154.       }
  155.  
  156.       return var2;
  157.    }
  158.  
  159.    public short GetState() {
  160.       return this.m_wState;
  161.    }
  162.  
  163.    public boolean OnMouseClick(int var1, int var2, Point var3, int var4, CRect var5) {
  164.       if (var4 == 7) {
  165.          if (((CDisplayResponse)this).HitTest(var3) && var1 == 2022 && !Utils.StateTest(this.m_wState, 8)) {
  166.             this.m_wState = (short)Utils.StateSet(this.m_wState, 8);
  167.             Globals.thePresView.Render(this.m_rcSymbol);
  168.             Globals.thePresView.Draw((Graphics)null, this.m_rcSymbol);
  169.          } else if (var1 == 2023 && Utils.StateTest(this.m_wState, 8)) {
  170.             this.m_wState = (short)Utils.StateClear(this.m_wState, 8);
  171.             if (Utils.StateTest(this.m_wState, 4)) {
  172.                this.m_wState = (short)Utils.StateClear(this.m_wState, 4);
  173.             } else if ((this.m_nFlags & 128) == 0 || Utils.StateTest(this.m_wState, 16) && !Utils.StateTest(this.m_wState, 16)) {
  174.                if ((this.m_nFlags & 64) != 0) {
  175.                   this.ToggleState();
  176.                }
  177.             } else {
  178.                this.ResetRadioButtonGroup();
  179.                this.m_wState = (short)Utils.StateSet(this.m_wState, 16);
  180.                Globals.thePresView.Render(this.m_rcSymbol);
  181.                Globals.thePresView.Draw((Graphics)null, this.m_rcSymbol);
  182.             }
  183.          }
  184.       }
  185.  
  186.       return false;
  187.    }
  188.  
  189.    public boolean SetResponse() {
  190.       if (!((CDisplayResponse)this).GetActualRect().isEmpty()) {
  191.          boolean var1 = false;
  192.          String var2 = Utils.InsertVariablesInString(this.m_strText);
  193.          if (!var2.equals(this.m_strVarText)) {
  194.             this.m_strVarText = var2;
  195.             var1 = true;
  196.          }
  197.  
  198.          if ((this.m_nFlags & 8) != 0 && !Utils.StateTest(this.m_wState, 16)) {
  199.             if ((this.m_nFlags & 128) != 0) {
  200.                this.ResetRadioButtonGroup();
  201.             }
  202.  
  203.             this.m_wState = 16;
  204.             var1 = true;
  205.          } else if (this.m_strSetExpression.length() > 0) {
  206.             if (Utils.CheckExpression(this.m_strSetExpression, false)) {
  207.                if (!Utils.StateTest(this.m_wState, 16)) {
  208.                   if ((this.m_nFlags & 128) != 0) {
  209.                      this.ResetRadioButtonGroup();
  210.                   }
  211.  
  212.                   this.m_wState = 16;
  213.                   var1 = true;
  214.                }
  215.             } else if (Utils.StateTest(this.m_wState, 16)) {
  216.                this.m_wState = (short)Utils.StateClear(this.m_wState, 16);
  217.                var1 = true;
  218.             }
  219.          }
  220.  
  221.          if (!((CDisplayResponse)this).GetActualRect().equals(((CDisplayResponse)this).GetDrawRect())) {
  222.             if (!((CDisplayResponse)this).GetDrawRect().isEmpty()) {
  223.                Globals.thePresView.InvalidateOffScreenRect(((CDisplayResponse)this).GetDrawRect());
  224.             }
  225.  
  226.             ((CDisplayResponse)this).SetDrawRect(((CDisplayResponse)this).GetActualRect());
  227.             var1 = true;
  228.          }
  229.  
  230.          Globals.thePresView.AddDrawObject((CIconObject)this, 1024, var1);
  231.       }
  232.  
  233.       return true;
  234.    }
  235.  
  236.    public boolean OnMouseMove(int var1, Point var2, int var3, CRect var4) {
  237.       if (var3 == 7 && Utils.StateTest(this.m_wState, 8)) {
  238.          if (((CDisplayResponse)this).HitTest(var2) && Utils.StateTest(this.m_wState, 4)) {
  239.             this.m_wState = (short)Utils.StateClear(this.m_wState, 4);
  240.             Globals.thePresView.Render(this.m_rcSymbol);
  241.             Globals.thePresView.Draw((Graphics)null, this.m_rcSymbol);
  242.          } else if (!((CDisplayResponse)this).HitTest(var2) && !Utils.StateTest(this.m_wState, 4)) {
  243.             this.m_wState = (short)Utils.StateSet(this.m_wState, 4);
  244.             Globals.thePresView.Render(this.m_rcSymbol);
  245.             Globals.thePresView.Draw((Graphics)null, this.m_rcSymbol);
  246.          }
  247.       }
  248.  
  249.       return false;
  250.    }
  251.  
  252.    public void DrawObject(Graphics var1, int var2, CRect var3) {
  253.       Graphics var4 = var1.create();
  254.       var4.clipRect(var3.x, var3.y, var3.width, var3.height);
  255.       this.m_rcSymbol.width = this.m_rcSymbol.height = Math.min(Toolkit.getDefaultToolkit().getFontMetrics(this.m_Font.GetFont()).getHeight(), var3.height);
  256.       this.m_rcSymbol.y = var3.y + (var3.height - this.m_rcSymbol.height) / 2;
  257.       CRect var5 = new CRect();
  258.       var4.setFont(this.m_Font.GetFont());
  259.       var5.height = var3.height;
  260.       var5.width = Math.max(var3.width - this.m_rcSymbol.width - 5, 0);
  261.       var5.height = Math.min(Utils.DrawText(var4, this.m_strVarText, var5, 33).height, var3.height);
  262.       var5.y = var3.y + (var3.height - var5.height) / 2;
  263.       if ((this.m_nFlags & 1) != 0) {
  264.          this.m_rcSymbol.x = var3.x + var5.width + 5;
  265.          var5.x = var3.x;
  266.       } else {
  267.          this.m_rcSymbol.x = var3.x;
  268.          var5.x = var3.x + this.m_rcSymbol.width + 5;
  269.       }
  270.  
  271.       if ((this.m_nFlags & 16) != 0) {
  272.          var4.setColor(this.m_rgbBg);
  273.          var4.fillRect(var3.x, var3.y, var3.width, var3.height);
  274.       }
  275.  
  276.       var4.setColor(this.m_rgbFg);
  277.       if (this.m_strVarText.length() > 0) {
  278.          Utils.DrawText(var4, this.m_strVarText, var5, 1);
  279.       }
  280.  
  281.       if ((this.m_nFlags & 128) != 0) {
  282.          var4.drawOval(this.m_rcSymbol.x, this.m_rcSymbol.y, this.m_rcSymbol.width, this.m_rcSymbol.height);
  283.          if (Utils.StateTest(this.m_wState, 8) && !Utils.StateTest(this.m_wState, 4)) {
  284.             var4.drawOval(this.m_rcSymbol.x + 1, this.m_rcSymbol.y + 1, this.m_rcSymbol.width - 2, this.m_rcSymbol.height - 2);
  285.          }
  286.  
  287.          if (Utils.StateTest(this.m_wState, 16)) {
  288.             var4.fillOval(this.m_rcSymbol.x + 3, this.m_rcSymbol.y + 3, this.m_rcSymbol.width - 5, this.m_rcSymbol.height - 5);
  289.             return;
  290.          }
  291.       } else if ((this.m_nFlags & 64) != 0) {
  292.          var4.drawRect(this.m_rcSymbol.x, this.m_rcSymbol.y, this.m_rcSymbol.width, this.m_rcSymbol.height);
  293.          if (Utils.StateTest(this.m_wState, 8) && !Utils.StateTest(this.m_wState, 4)) {
  294.             var4.drawRect(this.m_rcSymbol.x + 1, this.m_rcSymbol.y + 1, this.m_rcSymbol.width - 2, this.m_rcSymbol.height - 2);
  295.          }
  296.  
  297.          if (Utils.StateTest(this.m_wState, 16)) {
  298.             var4.drawLine(this.m_rcSymbol.x + 3, this.m_rcSymbol.y + 3, this.m_rcSymbol.x + this.m_rcSymbol.width - 3, this.m_rcSymbol.y + this.m_rcSymbol.height - 3);
  299.             var4.drawLine(this.m_rcSymbol.x + 3, this.m_rcSymbol.y + this.m_rcSymbol.height - 3, this.m_rcSymbol.x + this.m_rcSymbol.width - 3, this.m_rcSymbol.y + 3);
  300.          }
  301.       }
  302.  
  303.    }
  304. }
  305.